﻿using System;
using System.Windows.Forms;
using BCS.Business;
using BCS.Common;

namespace BCS.WinFormAppGui
{
        public partial class CameraAeraForm : Form
        {
                public int Step { get; set; }

                public String AreaName { get; set; }

                private BusinessCache cache = BusinessCache.Instance;

                public CameraAeraForm()
                {
                        InitializeComponent();
                }

                private void Form_Loaded(object sender, EventArgs e)
                {
                        for (int i = 1; i < 13; i++)
                        {
                                StepComboBox.Items.Add(i);
                        }

                        StepComboBox.SelectedIndex = 0;
                }

                private void StepComboBox_SelectedIndexChanged(object sender, EventArgs e)
                {
                        Step = Convert.ToInt32(StepComboBox.SelectedItem.ToString());
                }

                private void UpButton_Click(object sender, EventArgs e)
                {
                        switch (AreaName)
                        {
                                case "Fore":

                                        cache.Camera.ForeY -= Step;

                                        if (cache.Camera.ForeY < 10)
                                        {
                                                cache.Camera.ForeY = 10;
                                        }
                                        break;

                                case "Back":

                                        cache.Camera.BackY -= Step;

                                        if (cache.Camera.BackY < 10)
                                        {
                                                cache.Camera.BackY = 10;
                                        }
                                        break;

                                default: break;
                        }

                        cache.Save();
                }

                private void DownButton_Click(object sender, EventArgs e)
                {
                        switch (AreaName)
                        {
                                case "Fore":
                                        cache.Camera.ForeY += Step;

                                        if (cache.Camera.ForeY + Global.AeraHeight > 566)
                                        {
                                                cache.Camera.ForeY = 566 - Global.AeraHeight;
                                        }
                                        break;

                                case "Back":
                                        cache.Camera.BackY += Step;

                                        if (cache.Camera.BackY + Global.AeraHeight > 566)
                                        {
                                                cache.Camera.BackY = 566 - Global.AeraHeight;
                                        }
                                        break;

                                default: break;
                        }

                        cache.Save();
                }

                private void LeftButton_Click(object sender, EventArgs e)
                {
                        switch (AreaName)
                        {
                                case "Fore":
                                        cache.Camera.ForeX -= Step;

                                        if (cache.Camera.ForeX < 10)
                                        {
                                                cache.Camera.ForeX = 10;
                                        }
                                        break;

                                case "Back":
                                        cache.Camera.BackX -= Step;

                                        if (cache.Camera.BackX < 10)
                                        {
                                                cache.Camera.BackX = 10;
                                        }
                                        break;

                                default: break;
                        }

                        cache.Save();
                }

                private void RightButton_Click(object sender, EventArgs e)
                {
                        switch (AreaName)
                        {
                                case "Fore":
                                        cache.Camera.ForeX += Step;

                                        if (cache.Camera.ForeX + Global.AeraWidth > 758)
                                        {
                                                cache.Camera.ForeX = 758 - Global.AeraWidth;
                                        }
                                        break;

                                case "Back":
                                        cache.Camera.BackX += Step;

                                        if (cache.Camera.BackX + Global.AeraWidth > 758)
                                        {
                                                cache.Camera.BackX = 758 - Global.AeraWidth;
                                        }
                                        break;

                                default: break;
                        }

                        cache.Save();
                }
        }
}